home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / DICE.BAS < prev    next >
BASIC Source File  |  1989-08-31  |  834b  |  30 lines

  1. ' DICE.BAS
  2. ' This program asks the user to enter how many times the QuickBASIC
  3. '   Interpreter should "roll" two dice, and then calculates how many
  4. '   times the number 7 comes up.
  5.  
  6. CLS
  7.  
  8. RANDOMIZE TIMER
  9.  
  10. COLOR 4             ' red color for title
  11. PRINT "DICE-SIMULATION PROGRAM"
  12. COLOR 7             ' restore default white color
  13. PRINT
  14. numSeven% = 0       ' start with 7 counter equal to zero
  15.  
  16. INPUT "How many times should I roll the dice?  ", rolls%
  17. PRINT
  18. PRINT "Working..."  ' make sure the user knows nothing is wrong
  19.  
  20. FOR i% = 1 TO rolls%
  21.     die1% = INT(RND * 7)       ' "roll" the first die
  22.     die2% = INT(RND * 7)       ' "roll" the second die
  23.     IF die1% + die2% = 7 THEN numSeven% = numSeven% + 1
  24. NEXT i%
  25.  
  26. PRINT
  27. PRINT "Out of"; rolls%; "rolls, the number 7 came"
  28. PRINT "up"; numSeven%; "times."
  29.  
  30.